<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include("settings.php");

class Contacts extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/Contacts
	 *	- or -  
	 * 		http://example.com/index.php/Contacts/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/Contacts/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
    
	public function index()
	{
        $data['email'] = $this->info->email;
    	$data['working_hours'] = $this->info->working_hours;
    	$data['address'] = $this->info->address;
    	$data['welcome'] = $this->info->welcome;
 		$data['collections'] = $this->info->collections;
        $data['phone'] = $this->info->phone_number;
		$data['latests'] = $this->info->latest_images;
		$this->parser->parse("contacts.tpl", $data);
	}
	
	public function feedback()
	{
		//validate form input
		$this->form_validation->set_rules('name', 'Name', 'required');
		$this->form_validation->set_rules('email', 'Email', 'required');
		$this->form_validation->set_rules('message', 'Message ', 'required');
				
		if ($this->form_validation->run() == true)
		{ // check to see if the form was filled properly
			$inputs['name'] = $this->input->post('name', TRUE);
			$inputs['email'] = $this->input->post('email', TRUE);
			$inputs['website'] = $this->input->post('website', TRUE);
			$inputs['message'] = $this->input->post('message', TRUE);
			$this->tdatabase->insert_entry($inputs, 'feedback');
		} else {  // form was not filled properly
			//set the flash data error message if there is one
			$data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
		}
		$this->index();
	}

	public function __construct()
	{
		parent::__construct();
        $this->load->database();
		$this->load->model('tdatabase_model', 'tdatabase');
        $this->load->model('images_model', 'images');
        $this->load->model('info_model', 'info');
		$this->load->library(array('form_validation', 'session'));
	}

}

/* End of file Contacts.php */
/* Location: ./application/controllers/Contacts.php */
